#!/bin/bash

set -e -u

# configure locale
ln -sf /usr/share/zoneinfo/UTC /etc/localtime
sed -i 's/#\(en_US\.UTF-8\)/\1/' /etc/locale.gen
sed -i 's/#\(es_ES\.UTF-8\)/\1/' /etc/locale.gen
sed -i 's/#\(gl_ES\.UTF-8\)/\1/' /etc/locale.gen
sed -i 's/#\(pt_BR\.UTF-8\)/\1/' /etc/locale.gen
locale-gen

# configure sudo
chmod 750 /etc/sudoers.d
chmod 440 /etc/sudoers.d/g_wheel

# configure pacman
sed -i "s/#Server/Server/g" /etc/pacman.d/mirrorlist

# configure services
# TODO:
# systemctl enable multi-user.target      \
#                  pacman-init.service    \
#                  choose-mirror.service  \
#                  NetworkManager.service

# configure root shell
usermod -s /usr/bin/zsh root 2> /dev/null

# configure live user and login
LIVE_USER=parabola
LIVE_USER_GROUPS="adm,audio,floppy,log,network,rfkill,scanner,storage,optical,power,wheel"
[ -z "`id ${LIVE_USER} 2> /dev/null`" ] && useradd -m -p "" -g users -G "$LIVE_USER_GROUPS" -s /usr/bin/zsh ${LIVE_USER}
cp /usr/share/applications/calamares.desktop /home/liveuser/Desktop/
cp -r /home/liveuser/. /home/${LIVE_USER}/
chown -R ${LIVE_USER}:users /home/${LIVE_USER}/
rm -rf /home/liveuser
# TODO:
# sed -i "s|--autologin root|--autologin ${LIVE_USER}|" /etc/systemd/system/getty@tty1.service.d/autologin.conf
sed -i "s|_EDITION_TITLE_|${iso_title}|" /etc/motd
# TODO:
# echo "@/home/${LIVE_USER}/.language.sh" >> /home/${LIVE_USER}/.config/lxsession/LXDE/autostart
